package com.xzlf.job;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xzlf.domain.SpringScheduledCron;
import com.xzlf.mapper.SpringScheduledCronMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

public abstract class ScheduleOfTask implements Runnable {
    @Autowired
    ApplicationContext applicationContext;
    @Autowired
    SpringScheduledCronMapper springScheduledCronMapper;

    protected abstract void exectue();

    /**
     * 实现控制定时任务启用或禁用的功能
     */
    @Override
    public void run() {
        String name = this.getClass().getName();
        SpringScheduledCron springScheduledCron = springScheduledCronMapper.selectOne(new LambdaQueryWrapper<SpringScheduledCron>()
                .eq(SpringScheduledCron::getCronKey, name));
        Byte status = springScheduledCron.getStatus();
        if (status.equals(new Byte("0"))){
            // 任务是禁用状态
            return;
        }
        exectue();
    }
}
